﻿using System.Dynamic;
using System.IO;
using System.Text;
using System.Web;
using Newtonsoft.Json;

namespace System
{
    public static class ObjectExtension
    {
        public static string ToJson(this ExpandoObject obj)
        {
            return JsonConvert.SerializeObject(obj);
        }
        public static string ToJson(this object obj)
        {
            if (obj == null)
            {
                return string.Empty;
            }
            return JsonConvert.SerializeObject(obj);
        }
        public static T JsonToObject<T>(this string json)
        {
            return JsonConvert.DeserializeObject<T>(json);
        }
    }
    
}